package hibernate;

import java.util.List;
import java.util.Set;
import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * Parkstab entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see hibernate.Parkstab
 * @author MyEclipse Persistence Tools
 */
public class ParkstabDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(ParkstabDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String TEL_NUMBER = "telNumber";
	public static final String TOTAL_SPACE = "totalSpace";
	public static final String EMPTY_SPACE = "emptySpace";
	public static final String DESCRIPTION = "description";
	public static final String ADDRESS = "address";
	public static final String LONGITUDE = "longitude";
	public static final String LATITUDE = "latitude";
	public static final String PRICE = "price";
	public static final String MAX_ORDER_TIME = "maxOrderTime";

	public void save(Parkstab transientInstance) {
		log.debug("saving Parkstab instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Parkstab persistentInstance) {
		log.debug("deleting Parkstab instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Parkstab findById(java.lang.Integer id) {
		log.debug("getting Parkstab instance with id: " + id);
		try {
			Parkstab instance = (Parkstab) getSession().get(
					"hibernate.Parkstab", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Parkstab instance) {
		log.debug("finding Parkstab instance by example");
		try {
			List results = getSession().createCriteria("hibernate.Parkstab")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Parkstab instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Parkstab as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByTelNumber(Object telNumber) {
		return findByProperty(TEL_NUMBER, telNumber);
	}

	public List findByTotalSpace(Object totalSpace) {
		return findByProperty(TOTAL_SPACE, totalSpace);
	}

	public List findByEmptySpace(Object emptySpace) {
		return findByProperty(EMPTY_SPACE, emptySpace);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByLongitude(Object longitude) {
		return findByProperty(LONGITUDE, longitude);
	}

	public List findByLatitude(Object latitude) {
		return findByProperty(LATITUDE, latitude);
	}

	public List findByPrice(Object price) {
		return findByProperty(PRICE, price);
	}

	public List findByMaxOrderTime(Object maxOrderTime) {
		return findByProperty(MAX_ORDER_TIME, maxOrderTime);
	}

	public List findAll() {
		log.debug("finding all Parkstab instances");
		try {
			String queryString = "from Parkstab";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Parkstab merge(Parkstab detachedInstance) {
		log.debug("merging Parkstab instance");
		try {
			Parkstab result = (Parkstab) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Parkstab instance) {
		log.debug("attaching dirty Parkstab instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Parkstab instance) {
		log.debug("attaching clean Parkstab instance");
		try {
			getSession().buildLockRequest(LockOptions.NONE).lock(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}